# 242. 有效的字母异位词
# 时间复杂度：O(n)，其中 n 为 s 的长度。
# 空间复杂度：O(S)，其中 S 为字符集大小，此处 S=26。
def isAnagram(s: str, t: str) -> bool:
    if len(s) != len(t):
        return False

    s_len = len(s)
    index = 0
    s_count_dict = {}
    t_count_dict = {}
    while index < s_len:
        s_char = s[index]
        t_char = t[index]

        s_count = s_count_dict.get(s_char, 0)
        t_count = t_count_dict.get(t_char, 0)

        s_count_dict[s_char] = s_count + 1
        t_count_dict[t_char] = t_count + 1

        index += 1

    for key in s_count_dict.keys():
        s_key_count = s_count_dict.get(key, 0)
        t_key_count = t_count_dict.get(key, 0)
        if s_key_count != t_key_count:
            return False

    return True


s = "anagram"
t = "nagaram"
result = isAnagram(s, t)
print(f"result:{result}")
